petitcomputerfandomcom-20200214-history
Petit Comp-- Tutorial 01: PRINT and simple INPUT
Introduction Welcome to the first a series of Petit Computer Tutorials, created to be easy to follow, so you can start programming faster! I hope that you learn from these tutorials! This will be covering Petit Computer for the DS, but it should work on other devices as well. ~boxtropica "Write a Program" Oh, hi there. I heard that you like Mudkipz. I also heard you like Petit Computer. If you like Petit Computer, you wanna learn how to program for it, right? OK, then! Let's boot up Petit Computer! Chances are you've already looked around the Petit Comp application, launched a few apps in "View Gallery", and maybe even downloaded games with the QR scanner. Either way, read on! Here we are, at the Petit Computer 'Home Menu'. Wonderful, isn't it? Ignore it's greatness, it'll distract you with the hypnotizing scrolling words in the background. Go ahead and give the 'Write Program' button on the touch screen a good punch. (Or touch, if you don't want to break your DS.) Wow! A terminal-like design? Don't be intimidated, it's very BASIC to understand. When you open up the 'Write Program', it defaults to 'Run' mode. 'Run' allows you to LOAD, SAVE, and RUN programs. It can also test commands. Besides 'Run' mode, there is also 'Edit' mode, but that's for later. PRINT Command Still in 'Run'? Good! Now, using the keyboard on the touch screen, type in the following: PRINT "Hello, world~" Ok, now hit the 'Enter' button on the horrid keyboard. You should see something like this: Hello, world~ See that pop up? Good. That means that your DS isn't broken. What did I have you type in, you asked? It's fairly obvious. (if the command doesn't give it away, the output should've...) 'PRINT', followed by a string/number, puts that text on the screen for all to read. It's not very handy in 'Run', but it will be in 'Edit'. "But wait, what's a String/Number have to do with PRINT?" Let me explain. Strings & Numbers Try typing PRINT 5 in 'Run', then hit enter. What do you see? This: 5 Get it? PRINT puts whatever you put after it onto the screen! Now, let's try PRINT HI And you see: 0 "What? Why did '0' pop up?" Well, my friend, that is because you entered a string as a number! Strings are text, and used in commands such as 'PRINT', need to be surrounded with quotation marks. Numbers can be used just the same as strings, just using numbers (Of course) and without quotation marks. Here is an example: PRINT "Hi!" Becomes- Hi! And PRINT 7 Becomes- 7 Of course you could just 'PRINT' numbers as strings (quotations), but not vice versa. Besides, why would you want to spend an extra 0.6 seconds typing two quotation marks when you could spend that time doing other things? You may wonder "Why even have numbers exsist when you could just have numbers as a string?" Well, that is because of MATH. Math is very handy, and very simple. Example- PRINT 7+3 You should see 10 It's that easy! 'PRINT' displays what follows it, and since 7+3 follows it, it goes ahead and displays the answer. (If you want 7+3 to be displayed, make it a string) This also works with subtraction (-), division (/), and multiplication (*). Simple INPUT OK, now go into the jungles of 'Edit'. Hit the EDIT button on the keyboard. Now you should see something that resembles 'Run', kinda. This allows you to write programs. Let's jump into INPUT. INPUT detects user input, and turns it into a value in a variable. PRINT "What's your name?" INPUT name$ PRINT "Hello, ";name$ See? INPUT stores what you type in as a string, and the string is stored in a variable. First- Let's dissect, then we will run the code. PRINT "What's your name?" If you learnt anything, you should know that this will display "What's your name?" on the screen. INPUT name$ INPUT lets you type in a string, and when you press enter, it saves that string as a variable. (In this case, the variable is called 'name$'. PRINT "Hello, ";name$ This displays "Hello, (what is entered as the INPUT string here)". The quotation marks end in the code after 'Hello,' because name$ isn't a string, it is a variable. The ; after "Hello," makes Petit Computer add 'name$' to the PRINT command. Variables are handled much like numbers, but variables ALWAYS have a $ in the end. ALWAYS. If there isn't a $, then Petit Comp. thinks it is a number. Now, to run the code, let's go back to 'Run'. Tap the 'RUN' button. Here we are, good ol' Run! Now, type "RUN" into 'Run', then push ENTER. That executes the code we typed in 'Edit'. You should see: What's your name? Now, type in your name, then press ENTER. Hello, (your name here) I hope it works. If not, then I made this tutorial incorrectly. Outward Well, I hope you learned how to use PRINT and about Numbers+Strings. I'll make a new tutorial soon, maybe. No promises! If you need any help (confused, etc.) feel free to contact me at "boxtropica@hotmail.com"! Happy Petit Computing! ~boxtropica Category:Resources Category:Tutorials